<template>
  <div>
      <h1>修改老师{{id}}</h1>
      老师名字:<input type="text" v-model="teacher.teacherName"><br>  
      老师密码:<input type="password" v-model="teacher.pwd"><br>
      性别:<input type="radio" v-model="teacher.sex" value="男">男
           <input type="radio" v-model="teacher.sex" value="女">女<br>
      类型: <select v-model="teacher.typeId">
                <option value="">--请选择--</option>
                <option v-for="(type,index) in typeList" :key="index" :value="type.id">{{type.city}}</option>
            </select>
      
      <br>
      学校: <br>
      入职日期:<input type="date" v-model="teacher.hireDate"><br>
      薪资:<input type="number" v-model="teacher.salary"><br>
      备注:<input type="text" v-model="teacher.remark"><br>     
      <input type="button" value="修改" @click="update()">

  </div>
</template>

<script>
export default {
    data() {
        return {
            id:null,
            teacher:{},
            typeList:[]
        }
    },
    methods: {
        async initTeacher(){
            let res = await this.$http.get("/teacher/"+this.id)
            // debugger
            this.teacher = res.data.data
        },
         //初始化老师类型的方法
        async initTypeList(){
            let res = await this.$http.get("/type/all")
            this.typeList = res.data.data
        },
        async update(){
            let res = await this.$http.put("/teacher",this.teacher)
            if(res.data.code==10000){
                alert("修改成功")
                this.$router.push("/teacherList")
            }else{
                alert("修改失败")
            }
        },
    },  
    created() {
        this.id = this.$route.params.id
        this.initTeacher()
        this.initTypeList()
    },
}
</script>

<style>

</style>